# -*- coding: iso-8859-1 -*-
#
#    This is part of Malvinas Argentinas Messenger
#
#    Malvinas Argentinas Messenger is free software; you can redistribute
#    it and/or modify it under the terms of the GNU General Public License
#    as published by the Free Software Foundation; either version 2 of the
#    License, or (at your option) any later version.
#
#    Malvinas Argentinas Messenger is distributed in the hope that it will be
#    useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with Malvinas Argentinas Messenger; if not, write to the Free
#    Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
#    MA  02110-1301  USA

#import dopy.tcp
#from dopy import *
import Pyro.core

class BusinessDelegate:
	def __init__(self, c):
		self.controller = c
		self.fachada = None

	def getFachada(self):
		try:
			if self.fachada is None:
				#self.controller.vista.debug("OK");
				#dopy.getHub()
				#self.fachada = tcp.remote('localhost', 9400, 'modelo')
				self.fachada = Pyro.core.getProxyForURI("PYROLOC://localhost:7766/modelo")
			return self.fachada
		except:
			self.controller.vista.debug("Error al intentar obtener fachada en Business Delegate")
			return
		
	def getConfig(self, p):
		fachada = self.getFachada()
		return fachada.getConfig(p)

	def __getstate___(self):
		return

	def prueba(self):
		fachada = self.getFachada()
		return fachada.prueba()
		
	def debug(self, texto):
		fachada = self.getFachada()
		fachada.debug(texto)

	def getContact(self, passport, contacto):
		fachada = self.getFachada()
		return fachada.getContact(passport, contacto)

	def getConversation(self, account, strPassport):
		fachada = self.getFachada()
		return fachada.getConversation(account, strPassport)

	def getConversations(self, account):
		fachada = self.getFachada()
		return fachada.getConversations(account)		

	def delConversation(self, account, contact):
		fachada = self.getFachada()
		return fachada.delConversation(account, contact)

	def delConversationText(self, account, contact):
		fachada = self.getFachada()
		return fachada.delConversationText(account, contact)

	def gotSingleConversation(self, account, contact):
		fachada = self.getFachada()
		return fachada.gotSingleConversation(account, contact)

	def addConversation(self, account, strPassport):
		fachada = self.getFachada()
		return fachada.addConversation(account, strPassport)

	def getContacts(self, passport):
		fachada = self.getFachada()
		return fachada.getContacts(passport)

	def sortContactList_Status(self, passport, lista):
		fachada = self.getFachada()
		return fachada.sortContactList_Status(passport, lista)

	def getGroups(self, passport):
		fachada = self.getFachada()
		return fachada.getGroups(passport)

	def closeSession(self, user, hash):
		fachada = self.getFachada()
		return fachada.closeSession(user, hash)

	def createSession(self, user, pwd, host, port, config):
		fachada = self.getFachada()
		return fachada.createSession(user, pwd, host, port, config)

	def chat(self, account, contact, ctime, msg):
		fachada = self.getFachada()
		return fachada.chat(account, contact, ctime, msg)

	def sendPendingMsg(self, account, contact):
		fachada = self.getFachada()
		return fachada.sendPendingMsg(account, contact)

	def getPendingMsg(self, account, contact):
		fachada = self.getFachada()
		return fachada.getPendingMsg(account, contact)

	def getPresence(self, account):
		fachada = self.getFachada()
		return fachada.getPresence(account)

	def setPresence(self, account, presence):
		fachada = self.getFachada()
		return fachada.setPresence(account, presence)

	def setNick(self, account, nick):
		fachada = self.getFachada()
		return fachada.setNick(account, nick)

	def setPersonalMessage(self, account, msg):
		fachada = self.getFachada()
		return fachada.setPersonalMessage(account, msg)

	def setMedia(self, account, media):
		fachada = self.getFachada()
		return fachada.setMedia(account, media)
